package model2D;

import context.*;

import mainFrame.MainFrame;

import javax.swing.table.AbstractTableModel;

import object2D.Object2D;

import java.util.Vector;

// ********************************************************************
// *** CLASS: ObjectTableModel
// ********************************************************************
public class ObjectTableModel extends AbstractTableModel implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  static final String TAG="mapEditor.map.ObjectTableModel";
  static final long serialVersionUID=0; // AD'HOC

  private Vector<Object2D> children;
  
  public void edit(int row) { children.elementAt(row).edit(); }
  public void select(int row)
  {	MainFrame.getCurrentDrawPanel().setSelected(children.elementAt(row)); }
  
  public int indexOf(Object2D obj) { return(children.indexOf(obj)); }


  // *************************************************************************
  // *** CONSTRUCTOR: ObjectTableModel
  // *************************************************************************
  public ObjectTableModel(Vector<Object2D> children)
  { this.children=children; }

  public int getColumnCount() { return(Object2D.getFieldNames().length); }
  public String getColumnName(int column) { return(Object2D.getFieldNames()[column]); }
  public int getRowCount() { return(children.size()); }
  
  public Object getValueAt(int row,int col)
  {	return(children.elementAt(row).getField(col)); }
  
  public void setValueAt(Object value,int row,int col)
  {	children.elementAt(row).setField(col,value);
//    tablePane.updateTable(); // TODO: ?????
    MainFrame.repaint();
  }
  

  public Class<?> getColumnClass(int c)
  { return getValueAt(0, c).getClass(); }
  
  public boolean isCellEditable(int row, int col)
  { return(getColumnClass(col) == String.class); }
  
}
